'use strict';

var _interopRequireDefault = require('@babel/runtime/helpers/interopRequireDefault');
Object.defineProperty(exports, '__esModule', {
  value: true,
});
exports.default = void 0;
var _slicedToArray2 = _interopRequireDefault(require('@babel/runtime/helpers/slicedToArray'));
var _react = _interopRequireDefault(require('react'));
var _antd = require('antd');
var _sortedUniq = _interopRequireDefault(require('lodash/sortedUniq'));
var _FormContext = require('../contexts/FormContext');
/**
 * WhenWrap 逻辑隐藏容器
 * @param props
 * @returns
 */
var WhenWrap = function WhenWrap(_ref) {
  var when = _ref.when,
    children = _ref.children;
  var form = (0, _FormContext.useFormContext)();
  if (when) {
    var _ref2 = when !== null && when !== void 0 ? when : [],
      _ref3 = (0, _slicedToArray2.default)(_ref2, 2),
      _ref3$ = _ref3[0],
      predicate =
        _ref3$ === void 0
          ? function () {
              return true;
            }
          : _ref3$,
      _ref3$2 = _ref3[1],
      dependencies = _ref3$2 === void 0 ? [] : _ref3$2;
    return /*#__PURE__*/ _react.default.createElement(
      _antd.Form.Item,
      {
        noStyle: true,
        dependencies: (0, _sortedUniq.default)(dependencies),
      },
      function (_ref4) {
        var getFieldsValue = _ref4.getFieldsValue;
        var vals = getFieldsValue();
        var predicated = predicate(vals, form);
        return predicated ? children : null;
      },
    );
  }
  return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, children);
};
var _default = WhenWrap;
exports.default = _default;
